
#include "VarArray.hpp"
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;
void ThomasAlgorithm(VarArray<double, 2, 0> &coefficient_matrix, double *value,
                     int begin, int end);

template <typename T> void PrintForCheck(const VarArray<T, 2, 0> &vv) {
  int ni = vv.Dim(0);
  int nj = vv.Dim(1);

  for (int j = 0; j < nj; ++j) {
    for (int i = 0; i < ni; ++i) {
      cout << (vv(i, j)) << "\t";
    }
    cout << endl << endl;
  }
}

// 测试通过
int main() {
  VarArray<double, 2, 0> coeff(3, 6);
  coeff(1, 1) = 1.0;
  coeff(2, 1) = 2.0;

  coeff(0, 2) = 2.0;
  coeff(1, 2) = 3.0;
  coeff(2, 2) = 1.0;

  coeff(0, 3) = 5;
  coeff(1, 3) = 2;
  coeff(2, 3) = -4;

  coeff(0, 4) = 2;
  coeff(1, 4) = 3;
  PrintForCheck(coeff);
  vector<double> result(6);
  result[1] = 5;
  result[2] = 11;
  result[3] = 20;
  result[4] = 3;

  ThomasAlgorithm(coeff, result.data(), 1, result.size()-1);
  cout << result[4] << "\t" << result[1] << "\t" << result[2] << "\t"
       << result[3] << endl;
  return 0;
}